﻿using Garnet;
using Garnet.server;
using Garnet.server.Auth.Settings;
using System.Net;

namespace GarnetServerSample
{
    /// <summary>
    /// https://microsoft.github.io/garnet/docs/welcome/releases
    /// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // 配置服务器参数
                var options = new GarnetServerOptions
                {
                    EndPoints = [new IPEndPoint(IPAddress.Loopback, 6379)],//监听地址和端口
                    MetricsSamplingFrequency = 1000,//指标采样频率(ms)
                    CheckpointDir = "./checkpoints",//检查点目录
                    EnableStorageTier = false,//是否启用持久化存储层
                    IndexSize = "8g",//索引大小
                    MemorySize = "16g",//工作内存大小
                    PageSize = "32m",//内存页大小
                    SegmentSize = "1g",//内存段大小
                    LogDir = "./data",//数据目录
                    ThreadPoolMaxThreads = Environment.ProcessorCount,//最大工作线程数
                    AuthSettings = new Garnet.server.Auth.Settings.NoAuthSettings(),//无密码
                    //AuthSettings= new Garnet.server.Auth.Settings.PasswordAuthenticationSettings("123qwe"),//设置密码
                };

                using var server = new GarnetServer(args);
                server.Start();//net托管Garnet  127.0.0.1 Port: 6379
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to initialize server due to exception: {ex.Message}");
            }
        }
    }
}
